<?php
/**
 * Api基础控制器
 */

namespace app\api\controller;

use think\App;
use think\Request;
use app\api\traits\ApiAuth;
use think\Controller;
use tools\Crypt;
class ApiBase extends Controller
{
    use ApiAuth;

    //无需验证登录的方法，禁止在此处修改,请在具体业务Controller中修改
    protected $authExcept = [];

    //当前访问的用户
    protected $uid = 0;

    //当前页码
    protected $page;

    //每页数据量
    protected $limit;

    /**
     * @var Request
     */
    protected $request;


    //当前请求的参数，get/post都在其中
    protected $param;

    //当前请求数据的ID
    protected $id;

    public function initialize()
    {
        header('Access-Control-Allow-Origin:*');
        header("Access-Control-Allow-Headers:token, Origin, X-Requested-With, Content-Type, Accept, Authorization");
        header('Access-Control-Allow-Methods:POST,GET,PUT,DELETE');
        header("Access-Control-Max-Age:1728000");
        if (request()->isOptions()) { //浏览器的option试探请求，要exit掉，不然你的业务会被执行两次
            exit();
        }
        $request = $this->request;
        //jwt验证
        // $this->jtwInit();
        // $this->checkToken();

        //初始化基本数据
        $this->param = $request->param();

        $this->page  = $this->param['page'] ?? 1;
        $this->limit = $this->param['size'] ?? 10;
        $this->id    = $this->param['id'] ?? 0;
         $uid=$this->param['uid'] ?? 0;
        $this->uid    =$uid ?? 0;

        //limit防止过大处理
        $this->limit = $this->limit <= 100 ? $this->limit : 100;
    }


}